package com.woniu.microcommunityserver.tribal.mapper;

import com.woniu.microcommunityserver.book.entity.BookInformationInfoEntity;
import com.woniu.microcommunityserver.tribal.entity.PosterCommentInfoEntity;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface PosterCommentInfoMapper {
    /**
     * 新增评论
     * @param posterCommentInfoEntity
     * @return
     */
    @Insert("insert into poster_comment_info(comment_information,fk_poster_id," +
            "comment_state,fk_user_id,comment_time,reply_id) values(#{p.commentInformation}," +
            "#{p.fkPosterId},#{p.commentState},#{p.fkUserId},#{p.commentTime},#{p.replyId})")
    boolean insert(@Param("p") PosterCommentInfoEntity posterCommentInfoEntity);

    @Select("select id,comment_information,fk_poster_id,comment_state,fk_user_id,comment_time," +
            "reply_id from poster_comment_info where comment_state=0 and reply_id=0 and fk_poster_id=#{fkPosterId} " +
            "order by comment_time")
    @Results({
            @Result(id=true,column="id",property="id"),
            @Result(column="comment_information",property="commentInformation"),
            @Result(column="fk_poster_id",property="fkPosterId"),
            @Result(column="comment_state",property="commentState"),
            @Result(column="fk_user_id",property="fkUserId"),
            @Result(column="comment_time",property="commentTime"),
            @Result(column="reply_id",property="replyId"),
            @Result(column="id",property="posterCommentInfoEntity",javaType = List.class,
                    many=@Many(
                            select="com.woniu.microcommunityserver.tribal.mapper.PosterCommentInfoMapper.findOther",fetchType = FetchType.EAGER
                    ))
    })
    List<PosterCommentInfoEntity> findAll(Integer fkPosterId);


    @Select("select id,comment_information,fk_poster_id,comment_state,fk_user_id,comment_time," +
            "reply_id from poster_comment_info where reply_id=#{id}")
    @Results({
            @Result(id=true,column="id",property="id"),
            @Result(column="comment_information",property="commentInformation"),
            @Result(column="fk_poster_id",property="fkPosterId"),
            @Result(column="comment_state",property="commentState"),
            @Result(column="fk_user_id",property="fkUserId"),
            @Result(column="comment_time",property="commentTime"),
            @Result(column="reply_id",property="replyId"),
            @Result(column="id",property="posterCommentInfoEntity",javaType = List.class,
                    many=@Many(
                            select="com.woniu.microcommunityserver.tribal.mapper.PosterCommentInfoMapper.findOther",fetchType = FetchType.EAGER
                    ))
    })
    List<PosterCommentInfoEntity> findOther(Long id);
}
